package interview.juc;
class Ticker{
    private int num =40;

    public synchronized void sale(){
        for (int i = 0; i < 40; i++) {
            if(num > 0){
                System.out.println(Thread.currentThread().getName()+"卖了一张票，还剩"+ --num +"张票。");
            }
        }

    }
}
public class Juc02_01Lock {
    public static void main(String[] args) {
        sale();
    }

    /**
     * 第一个卖票案例
     */
    private static void sale() {
        Ticker ticker = new Ticker();
        new Thread(ticker::sale,"A").start();
        new Thread(ticker::sale,"A").start();
        new Thread(ticker::sale,"A").start();
    }
}
